package com.zl.autocode.controller.autocode;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zl.autocode.controller.base.AutocodeBaseController;
import com.zl.autocode.dto.autocode.table.ReqTableAddDTO;
import com.zl.autocode.dto.autocode.table.ReqTableDelDTO;
import com.zl.autocode.dto.autocode.table.ReqTableDetailDTO;
import com.zl.autocode.dto.autocode.table.ReqTableEditDTO;
import com.zl.autocode.dto.autocode.table.ReqTableQueryDTO;
import com.zl.autocode.dto.autocode.table.ReqTableStateDTO;
import com.zl.autocode.dto.autocode.table.ResTableAddDTO;
import com.zl.autocode.dto.autocode.table.ResTableDelDTO;
import com.zl.autocode.dto.autocode.table.ResTableDetailDTO;
import com.zl.autocode.dto.autocode.table.ResTableEditDTO;
import com.zl.autocode.dto.autocode.table.ResTableQueryDTO;
import com.zl.autocode.dto.autocode.table.ResTableStateDTO;
import com.zl.autocode.service.autocode.ITableService;
import com.zl.common.aop.LogSimpleResult;
import com.zl.common.dto.ReqDTO;
import com.zl.common.dto.ResDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 数据库表信息
 * @author ZL
 */
@Api(value="数据库表信息",tags ="数据库表信息")
@RestController("autocodeTableController")
@RequestMapping("/autocode/table")
public class TableController extends AutocodeBaseController {

    @Autowired
    private ITableService tableService;
    
    /**
     * 查询
     */
    @ApiOperation(value="数据库表信息-查询")
    @RequestMapping(value="/list", method = RequestMethod.POST)
    public ResDTO<ResTableQueryDTO> listTable(@RequestBody ReqDTO<ReqTableQueryDTO> reqInfo) throws Exception{
        ResTableQueryDTO data = tableService.queryTableList(reqInfo);
        return successDATA(data);
    }
    
   /**
     * 详情
     */
    @ApiOperation(value="数据库表信息-详情")
    @RequestMapping(value="/detail", method = RequestMethod.POST)
    public ResDTO<ResTableDetailDTO> detailTable(@RequestBody ReqDTO<ReqTableDetailDTO> reqInfo) throws Exception{
        ResTableDetailDTO data = tableService.queryTableDetail(reqInfo);
        return successDATA(data);
    }
    
    /**
     * 新增
     */
    @ApiOperation(value="数据库表信息-新增")
    @RequestMapping(value="/add", method = RequestMethod.POST)
        public ResDTO<ResTableAddDTO> addTable(@RequestBody ReqDTO<ReqTableAddDTO> reqInfo) throws Exception{
        ResTableAddDTO data = tableService.insertTableInfo(reqInfo);
        return successDATA(data);
    }
    
    /**
     * 编辑
     */
    @ApiOperation(value="数据库表信息-编辑")
    @RequestMapping(value="/edit", method = RequestMethod.POST)
        public ResDTO<ResTableEditDTO> editTable(@RequestBody ReqDTO<ReqTableEditDTO> reqInfo) throws Exception{
        ResTableEditDTO data = tableService.updateTableInfo(reqInfo);
        return successDATA(data);
    }
    
    /**
     * 删除
     */
    @ApiOperation(value="数据库表信息-删除")
    @RequestMapping(value="/del", method = RequestMethod.POST)
        public ResDTO<ResTableDelDTO> delTable(@RequestBody ReqDTO<ReqTableDelDTO> reqInfo) throws Exception{
        ResTableDelDTO data = tableService.deleteTableInfo(reqInfo);
        return successDATA(data); 
    }
    
    /**
     * 状态更新
     */
    @ApiOperation(value="数据库表信息-状态更新")
    @RequestMapping(value="/state", method = RequestMethod.POST)
        public ResDTO<ResTableStateDTO> stateTable(@RequestBody ReqDTO<ReqTableStateDTO> reqInfo) throws Exception{
        ResTableStateDTO data = tableService.updateTableState(reqInfo);
        return successDATA(data); 
    }
    
    
    /**
     * 查询-包括字段
     */
    @ApiOperation(value="数据库表信息-查询")
    @LogSimpleResult
    @RequestMapping(value="/columnlist", method = RequestMethod.POST)
    public ResDTO<ResTableQueryDTO> listTableColumn(@RequestBody ReqDTO<ReqTableQueryDTO> reqInfo) throws Exception{
        ResTableQueryDTO data = tableService.queryTableColumnList(reqInfo);
        return successDATA(data);
    }
    
    /**
     * 删除
     */
    @ApiOperation(value="数据库表信息-删除全部")
    @RequestMapping(value="/delTableAndColumn", method = RequestMethod.POST)
        public ResDTO<ResTableDelDTO> delTableAll(@RequestBody ReqDTO<ReqTableDelDTO> reqInfo) throws Exception{
        ResTableDelDTO data = tableService.deleteTableAndColumn(reqInfo);
        return successDATA(data); 
    }
    
}